package model.domain;


import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "sprintbacklog", catalog = "scrum")
public class Task implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer taskID;
	private Product productbacklog;
	private Status status;
	private Person user;
	private String description;
	private String comments;
	private Date Start;
	private Date End;
	private Integer estimatedEffort;
	private Integer currentEffort;

	public Task() {
	}

	public Task(Product productbacklog, Status status,
			String cdescription) {
		this.productbacklog = productbacklog;
		this.status = status;
		this.description = cdescription;
	}

	public Task(Product productbacklog, Status status,
			Person user, String cdescription, String ccomments,
			Date dtStart, Date dtEnd, Integer nestimatedEffort,
			Integer ncurrentEffort) {
		this.productbacklog = productbacklog;
		this.status = status;
		this.user = user;
		this.description = cdescription;
		this.comments = ccomments;
		this.Start = dtStart;
		this.End = dtEnd;
		this.estimatedEffort = nestimatedEffort;
		this.currentEffort = ncurrentEffort;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "nTaskID", unique = true, nullable = false)
	public Integer getTaskID() {
		return this.taskID;
	}

	public void setTaskID(Integer ntaskId) {
		this.taskID = ntaskId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nPBID", nullable = false)
	public Product getProductbacklog() {
		return this.productbacklog;
	}

	public void setProductbacklog(Product productbacklog) {
		this.productbacklog = productbacklog;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nStatusID", nullable = false)
	public Status getStatus() {
		return this.status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "nAssignedID")
	public Person getUser() {
		return this.user;
	}

	public void setUser(Person user) {
		this.user = user;
	}

	@Column(name = "cDescription", nullable = false, length = 50)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String cdescription) {
		this.description = cdescription;
	}

	@Column(name = "cComments", length = 500)
	public String getComments() {
		return this.comments;
	}

	public void setComments(String ccomments) {
		this.comments = ccomments;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dtStart", length = 19)
	public Date getStart() {
		return this.Start;
	}

	public void setStart(Date dtStart) {
		this.Start = dtStart;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dtEnd", length = 19)
	public Date getEnd() {
		return this.End;
	}

	public void setEnd(Date dtEnd) {
		this.End = dtEnd;
	}

	@Column(name = "nEstimatedEffort")
	public Integer getEstimatedEffort() {
		return this.estimatedEffort;
	}

	public void setEstimatedEffort(Integer nestimatedEffort) {
		this.estimatedEffort = nestimatedEffort;
	}



    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }
        final Task other = (Task) obj;
        if(this.taskID == null){
            if(other.getTaskID() != null){
                return false;
            }
        } else if(!this.taskID.equals(other.getTaskID())){
            return false;
        }
        return true;

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.taskID != null ? this.taskID.hashCode() : 0);
        hash = 47 * hash + (this.description != null ? this.description.hashCode() : 0);
        return hash;
    }
}
